import { queryDetail, modif } from './service';
import { routerRedux } from 'dva/router';

import { queryDictList } from '@/services/dict';

export default {
	namespace: 'micro',

	state: {
		tableData: [
			// {
      //   key: '站长',
      //   name: '1',
      //   age: '2',
      //   kind: '站长',
      //   gender: '男',
      //   mobile: '123',
      // },
      // {
      //   key: '消防员1',
      //   name: '1',
      //   age: '2',
      //   kind: '消防员',
      //   gender: '男',
      //   mobile: '123',
      // },
      // {
      //   key: '消防员2',
      //   name: '',
      //   age: '',
      //   kind: '消防员',
      //   gender: '男',
      //   mobile: '123',
      // },
		]
	},

	effects: {
		*queryInfo(_, { call, put }) {
			const response = yield call(queryDetail);
			yield put({ type: 'setInfo', payload: response });
		},
		*modif({ payload }, { call, put }) {
			yield call(modif, payload);
			yield put(routerRedux.push('/data/micro'));
		},
		*collectData({ payload }, {put}) {
			yield put({ type: 'setTableData', payload})
		}
	},

	reducers: {
		setInfo(state, action) {
			return {
				...state,
				details: action.payload
			};
		},
		setTableData(state, action) {
			return {
				...state,
				tableData: action.payload
			};
		}
	}
};
